import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAppStore = defineStore('app', () => {
  // 状态
  const loading = ref(false)
  const sidebarCollapse = ref(false)
  const breadcrumbs = ref<Array<{ title: string; path?: string }>>([])

  // 设置加载状态
  const setLoading = (value: boolean) => {
    loading.value = value
  }

  // 切换侧边栏折叠状态
  const toggleSidebar = () => {
    sidebarCollapse.value = !sidebarCollapse.value
  }

  // 设置面包屑
  const setBreadcrumbs = (crumbs: Array<{ title: string; path?: string }>) => {
    breadcrumbs.value = crumbs
  }

  return {
    // 状态
    loading,
    sidebarCollapse,
    breadcrumbs,

    // 方法
    setLoading,
    toggleSidebar,
    setBreadcrumbs
  }
})
